package com.ruoyi.SysCamera.controller;

import java.util.List;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.SysCamera.domain.City;
import com.ruoyi.SysCamera.service.ICityService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Operation;

/**
 * 区域管理Controller
 * 
 * @author ygr
 * @date 2024-03-22
 */
@RestController
@RequestMapping("/SysCamera/camera")
@Tag(name = "【区域管理】管理")
public class CityController extends BaseController
{
    @Autowired
    private ICityService cityService;

    /**
     * 查询区域管理列表
     */
    @Operation(summary = "查询区域管理列表")
    @PreAuthorize("@ss.hasPermi('SysCamera:camera:list')")
    @GetMapping("/list")
    public TableDataInfo list(City city)
    {
        startPage();
        List<City> list = cityService.selectCityList(city);
        return getDataTable(list);
    }

    /**
     * 导出区域管理列表
     */
    @Operation(summary = "导出区域管理列表")
    @PreAuthorize("@ss.hasPermi('SysCamera:camera:export')")
    @Log(title = "区域管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, City city)
    {
        List<City> list = cityService.selectCityList(city);
        ExcelUtil<City> util = new ExcelUtil<City>(City.class);
        util.exportExcel(response, list, "区域管理数据");
    }

    /**
     * 获取区域管理详细信息
     */
    @Operation(summary = "获取区域管理详细信息")
    @PreAuthorize("@ss.hasPermi('SysCamera:camera:query')")
    @GetMapping(value = "/{cityId}")
    public AjaxResult getInfo(@PathVariable("cityId") Long cityId)
    {
        return success(cityService.selectCityByCityId(cityId));
    }

    /**
     * 新增区域管理
     */
    @Operation(summary = "新增区域管理")
    @PreAuthorize("@ss.hasPermi('SysCamera:camera:add')")
    @Log(title = "区域管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody City city)
    {
        return toAjax(cityService.insertCity(city));
    }

    /**
     * 修改区域管理
     */
    @Operation(summary = "修改区域管理")
    @PreAuthorize("@ss.hasPermi('SysCamera:camera:edit')")
    @Log(title = "区域管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody City city)
    {
        return toAjax(cityService.updateCity(city));
    }

    /**
     * 删除区域管理
     */
    @Operation(summary = "删除区域管理")
    @PreAuthorize("@ss.hasPermi('SysCamera:camera:remove')")
    @Log(title = "区域管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{cityIds}")
    public AjaxResult remove(@PathVariable( name = "cityIds" ) Long[] cityIds) 
    {
        return toAjax(cityService.deleteCityByCityIds(cityIds));
    }
}
